package br.com.wayloc.track.libraries;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHandler extends SQLiteOpenHelper
{
	// Database Version
	private static final int DATABASE_VERSION = 1;
	// Database Name
	private static final String DATABASE_NAME = "waylocdata";

	public DatabaseHandler(Context context)
	{
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	// Creating Tables
	@Override
	public void onCreate(SQLiteDatabase db)
	{
		String CREATE_TABLE = "CREATE TABLE usuarios( "+
			"id INTEGER PRIMARY KEY AUTOINCREMENT, "+
			"login TEXT, "+
			"nome TEXT, "+
			"email TEXT, "+
			"descricao TEXT, "+
			"desde TEXT, "+
			"token TEXT )";
		db.execSQL(CREATE_TABLE);
	}

	// Upgrading database
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
	{
		// Drop older table if existed
		db.execSQL("DROP TABLE IF EXISTS usuarios");

		// Create tables again
		onCreate(db);
	}

	/*
	 * Apaga tabelas
	*/
	public void resetTables(){
		SQLiteDatabase db = this.getWritableDatabase();
		// Delete All Rows
		db.delete("usuarios", null, null);
		db.close();
	}
}